package com.lanmon.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.lanmon.entity.ComUser;

public class SystemInterceptor extends HandlerInterceptorAdapter{
	
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object arg2) throws Exception {
		Object userObj = request.getSession().getAttribute("user");
		ComUser user = null;
		if(userObj != null && userObj instanceof ComUser){
			user = (ComUser) userObj;
		}
		if(user != null){
			//System.out.println("session-user:"+user);
			return true;
		}else{
			request.getRequestDispatcher("/auth/loginpage").forward(request,response);
		}
		return false;
	}
	
}
